/**
 *
 * @User:   winter
 * @Date:   2019-08-21
 * @Time:   13:09
 *
 **/

var _DDNS = 'lifescience';
var _ENV = '';

$(document).ready(function () {
    window.COLLECT(_DDNS+ '-init'); //初始化
    new Swiper('.banner .swiper-container', {
        loop: true, // 循环模式选项
    });

    new Swiper(".testimonial_swiper_in_container", {
        pagination: {
            el: '.swiper-pagination',
            clickable: true,
        },
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
    });

    new Swiper(".applications_swiper .swiper-container", {
        slidesPerView: 3.5,
    });
});


$("#other_info_tab li").click(function () {
    $(this).addClass("active").siblings().removeClass("active");
    var _id = $(this).attr("data-id");
    $("#" + _id).addClass("active").siblings().removeClass("active");
});


$(".programme_msg").click(function () {
    if ($(this).hasClass("active")) {
        $(this).removeClass("active");
    } else {
        $(this).addClass("active").siblings().removeClass("active");
    }
});


function white_book(env) {
    _ENV = env;
    $("#white_book .modals").show(300);
    window.COLLECT(_DDNS + '-' + env); //初始化
};

function more_applications(env) {
    _ENV = env;
    window.COLLECT(_DDNS + '-' + env); //初始化
    $("#app_modals .modal-middle .title em").text("免费");
    $("#app_modals .modal-middle .title span").text("技术咨询，了解更多应用环境");
    $("#app_modals .modals").show(300);
};

function more_consultation(env) {
    _ENV = env;
    window.COLLECT(_DDNS + '-' + env); //初始化
    $("#app_modals .modal-middle .title em").text("快速获取");
    $("#app_modals .modal-middle .title span").text("技术专家咨询与技术支持");
    $("#app_modals .modals").show(300);
}

function showSubmit(text) {
    $("#submit_modals .modal-middle .msg").text(text);
    $("#submit_modals .modals").show(300);
}

$('.modal-dialog-flip .front .front-click').click(function () {
    $('.modal-dialog-flip .front').css({'transform': 'rotateY(-180deg)', 'z-index': '0'}).siblings().css({'transform': 'rotateY(0deg)', 'z-index': '1'})
});

$('.modal-dialog-flip .back .front-click').click(function () {
    $('.modal-dialog-flip .back').css({'transform': 'rotateY(-180deg)', 'z-index': '0'}).siblings().css({'transform': 'rotateY(0deg)', 'z-index': '1'})
});

function closeAll() {
    $("#white_book .modals").hide(100);
    $("#app_modals .modals").hide(100);
    $("#submit_modals .modals").hide(100);
    $(".modals input[name='eml']").val("");
    $(".modals input[name='email']").val("");
    $(".modals input[name='name']").val("");
    $(".modals input[name='phone']").val("");
};

var _eml_reg = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
var _phone_reg = /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/;

function white_book_submit() {
    var eml$ = $("#white_book .modals input[name='eml']").val();
    submitData({
        name: '',
        mobile: '',
        company: '',
        env: _DDNS + '-' + _ENV,
        email: eml$,
        position: '',
        resource: '',
    }, "工作人员将在1-3个工作日内添加您并为您发送生命科学白皮书");
};


function app_submit() {
    var name$ = $("#app_modals .modals input[name='name']").val();
    var phone$ = $("#app_modals .modals input[name='phone']").val();
    if (!name$) {
        alert('姓名不能为空');
        return;
    }

    if (!_phone_reg.test(phone$)) {
        alert('手机号有误，请重填');
        return;
    }

    submitData({
        name: name$,
        mobile: phone$,
        company: '',
        email: '',
        position: '',
        env: _DDNS + '-' + _ENV,
        resource: '',
    }, "我们将在1-3个工作日内与您联系，免费为您提供一对一技术咨询与支持！");
}

function submitData(data, text) {

    $.ajax({
        url: '//webapi.fastonetech.com/api/reservation/web',
        type: 'post',
        contentType: "application/json",
        data: JSON.stringify(data),
        dataType: "json",
        success: function (res) {
            showSubmit(text);
        },
    });
}
